﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="editTvStation.aspx.cs" Inherits="Com.CMS263.Web.manage.TvStation.editTvStation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
         <link href="../style/main.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.4.2.min.js" type="text/javascript"></script>
    <link href="../common/validator.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    .preview_fake{
             filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);     
    }     
</style>
    <style type="text/css">
        #title {
            width: 531px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        $(function() {
        $("#updateImage").hide();
        $("#updateImageBig").hide();
        })
        function checkNum(obj) {
            var tempstr;
            //先把非数字的都替换掉，除了数字和.   
            tempstr = obj.value.replace(/[^\d]/g, "");
            obj.value = tempstr;
        }

        function changeProvince() {
            var id = $("#txtProvince").val();
            $.post("/area_action.aspx?op=province", { id: id }, function(data) {
                $("#txtCity").html("");
                $("#txtArea").html("<option value='0'>区</option>");
                var province = data.split(';');

                $.each(province, function() {
                    if (this != "" && this.length > 0) {
                        var co = this.split(',');
                        $("#txtCity").append("<option value='" + co[0] + "'>" + co[1] + "</option>");
                    }
                })
                var cid = $("#txtCity").val();
                $.post("/area_action.aspx?op=city", { id: cid }, function(data) {
                    $("#txtArea").html("");
                    var city = data.split(';');

                    $.each(city, function() {
                        if (this != "" && this.length > 0) {
                            var co = this.split(',');
                            $("#txtArea").append("<option value='" + co[0] + "'>" + co[1] + "</option>");
                        }
                    })

                })
            })
        }
//        $(function() {
//            var id = $("#txtProvince").val();
//            $.post("/area_action.aspx?op=province", { id: id }, function(data) {
//                $("#txtCity").html("");
//                $("#txtArea").html("<option value='0'>区</option>");
//                var province = data.split(';');

//                $.each(province, function() {
//                    if (this != "" && this.length > 0) {
//                        var co = this.split(',');
//                        $("#txtCity").append("<option value='" + co[0] + "'>" + co[1] + "</option>");
//                    }
//                })
//                var cid = $("#txtCity").val();
//                $.post("/area_action.aspx?op=city", { id: cid }, function(data) {
//                    $("#txtArea").html("");
//                    var city = data.split(';');

//                    $.each(city, function() {
//                        if (this != "" && this.length > 0) {
//                            var co = this.split(',');
//                            $("#txtArea").append("<option value='" + co[0] + "'>" + co[1] + "</option>");
//                        }
//                    })

//                })
//            })

//        })
        function changeCity() {
            var id = $("#txtCity").val();
            $.post("/area_action.aspx?op=city", { id: id }, function(data) {
                $("#txtArea").html("");
                var city = data.split(';');

                $.each(city, function() {
                    if (this != "" && this.length > 0) {
                        var co = this.split(',');
                        $("#txtArea").append("<option value='" + co[0] + "'>" + co[1] + "</option>");
                    }
                })

            })
        } 
        function save() {
            if ($("#Name").val().length < 1) {
                alert("名称必填！");
                $("#Name").focus();
                return false;
            } else if ($("#LogoPic").val().length < 1) {
                alert("logo图必填！");
                $("#LogoPic").focus();
                return false;
            } else if ($("#txtProvince").val() =="0") {
                alert("省份必选！");
                $("#txtProvince").focus();
                return false;
            } else if ($("#txtCity").val() == "0") {
                alert("城市必选！");
                $("#txtCity").focus();
                return false;
            } else if ($("#txtArea").val() == "0") {
                alert("区必选！");
                $("#txtArea").focus();
                return false;
            } else if ($("#AdressRo").val().length < 1) {
                alert("地址必填！");
                $("#AdressRo").focus();
                return false;
            } else if ($("#BigPic").val().length < 1) {
                alert("大图必填！");
                $("#BigPic").focus();
                return false;
            } else if ($("#telePhone").val().length < 1) {
                alert("电话必填！");
                $("#telePhone").focus();
                return false;
            } else {
            return true;
            }
        }       
        $(document).ready(function() {
            $("#txtProvince option").each(function() {

                if ($(this).attr("value") == '<%=tv.ProvinceCode %>') {
                    $(this).attr("selected", "selected");
                }

            })
            $("#txtCity option").each(function() {

            if ($(this).attr("value") == '<%=tv.CityCode %>') {
                    $(this).attr("selected", "selected");
                }

            })
            $("#txtArea option").each(function() {

            if ($(this).attr("value") == '<%=tv.AreaCode %>') {
                    $(this).attr("selected", "selected");
                }

            })
        })
        function onUploadImgChange(sender, width, height, index) {
            $("#updateImage").show();        
            try {
                index = index == undefined ? "" : index;
                if (!sender.value.match(/.jpg|.gif|.png|.bmp/i)) {
                    alert('请上传.jpg|.gif|.png|.bmp类型的图片');
                    return false;
                }

                var objPreview = $(".preview_pic" + index);
                var objPreviewFake = document.getElementById('preview_fake' + index);

                if (sender.files && sender.files[0]) {
                    objPreview.show();
                    objPreview.attr("width", width);
                    objPreview.attr("height", height);

                    objPreview.attr("src", sender.files[0].getAsDataURL());



                } else if (objPreviewFake.filters) {
                    sender.select();
                    var imgSrc = document.selection.createRange().text;
                    objPreviewFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;

                    objPreviewFake.style.width = width + 'px';
                    objPreviewFake.style.height = height + 'px';
                    objPreview.hide();
                    sender.blur();
                }
            } catch (ex) {
                alert(ex);
                alert("图片加载失败！");
            }
        }
        function onUploadImgChangeBig(sender, width, height, index) {
            $("#updateImageBig").show();          
            try {
                index = index == undefined ? "" : index;
                if (!sender.value.match(/.jpg|.gif|.png|.bmp/i)) {
                    alert('请上传.jpg|.gif|.png|.bmp类型的图片');
                    return false;
                }

                var objPreview = $(".preview_picBig" + index);
                var objPreviewFake = document.getElementById('preview_fakeBig' + index);

                if (sender.files && sender.files[0]) {
                    objPreview.show();
                    objPreview.attr("width", width);
                    objPreview.attr("height", height);

                    objPreview.attr("src", sender.files[0].getAsDataURL());



                } else if (objPreviewFake.filters) {
                    sender.select();
                    var imgSrc = document.selection.createRange().text;
                    objPreviewFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;

                    objPreviewFake.style.width = width + 'px';
                    objPreviewFake.style.height = height + 'px';
                    objPreview.hide();
                    sender.blur();
                }
            } catch (ex) {
                alert(ex);
                alert("图片加载失败！");
            }
        }    
    </script>
</head>
<body>
    <form id="form1" runat="server" enctype="multipart/form-data">
    <input  id="Id" name="Id" value="<%=tv.Id %>" type="hidden"/>
    <input  id="pageTv" name="pageTv" value="<%=pageTv %>" type="hidden"/>
    <div>
        <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0" class="table_1">
            <tr>
                <td height="23" colspan="2" class="table_2">
                    添加/修改 <asp:label runat="server" id="lbTypeName">电视台</asp:label>
                </td>
            </tr>
            <tr>
                <td >
                    名称:
                </td>
                <td >
                 <input type="text" name="Name" id="Name" size="140" value="<%=tv.Name %>" />
                &nbsp;</td>
            </tr>  
            <tr>
                <td class="tdleft">
                    logo图(154*76)</td>
                <td class="tdside">                
              <img id="changeImg"  src="/ArtUpFile/<%=tv.LogoPic %>" width="100px" height="100px"/>                
                   
                            
                </td>
            </tr>
            <tr >
                <td class="tdleft">
                    设置新的logo图</td>
                <td class="tdside"> 
                    <input type='file'  name="LogoPic" id="LogoPic" value="<%=tv.LogoPic %>" onchange="onUploadImgChange(this,100,100);" /> 
                    <div id="updateImage">
      <div id="preview_fake" class="preview_fake">      
      <img  alt="" class="preview_pic" src="/ArtUpFile/<%=tv.LogoPic %>"   width="100px" height="100px"/>      
      </div> 
      </div>                    
                </td>
            </tr>
          <tr>
                <td class="tdleft">
                    地址</td>
                <td class="tdside">
                <select id="txtProvince" name="txtProvince" onchange="changeProvince()">
                <% foreach (Com.CMS263.PO.Province prov in provlist)
                   {%>
                <option value="<%=prov.Code %>">
                    <%=prov.Name %></option>
                <%} %>
            </select> <select id="txtCity" name="txtCity" onchange="changeCity()">
                <% foreach (Com.CMS263.PO.City city in citylist)
                   {%>
                <option value="<%=city.Code %>">
                    <%=city.Name%></option>
                <%} %>
            </select><select name="txtArea" id="txtArea">
                 <% foreach (Com.CMS263.PO.Area area in arealist)
                   {%>
                <option value="<%=area.Code %>">
                    <%=area.Name%></option>
                <%} %>
            </select>
                     <input type="text" name="AdressRo" id="AdressRo" value="<%=tv.AdressRo %>" size="50" />
                    
                </td>
            </tr>
            <tr>
                <td class="tdleft">
                    大图(203*245)：</td>
                <td class="tdside">
                 <img id="Img1"  src="/ArtUpFile/<%=tv.BigPic %>" width="150px" height="150px"/>
                </td>
            </tr>
            <tr>
                <td class="tdleft">
                    设置新的大图：</td>
                <td class="tdside">
                <input type='file'  name="BigPic" id="BigPic" value="<%=tv.BigPic %>" onchange="onUploadImgChangeBig(this,100,100);"/>                  
                      <div id="updateImageBig">
      <div id="preview_fakeBig" class="preview_fake">      
      <img  alt="" class="preview_picBig" src="/ArtUpFile/<%=tv.BigPic %>"   width="150px" height="150px"/>      
      </div> 
      </div>            
                </td>
            </tr>
             <tr>
                <td class="tdleft">
                    电话</td>
                <td class="tdside">
                <input type='text' value="<%=tv.TelePhone %>" name="telePhone" id="telePhone" onkeyup="checkNum(this);" onblur="checkNum(this);" size="25"/>                       
                    
                </td>
            </tr>
            <tr>
                    <td class="tdleft">
                       </td>
                    <td class="tdside">
                        <asp:Button ID="btnSave" runat="server" Text="保存" onclick="btnSave_Click"  OnClientClick="return save();" />                        

                        <input ID="Button1" value="返回" type="button" onclick="history.go(-1)" />                         
                    </td>
                </tr>
        </table>
    </div>
    </form>
</body>
</html>
